package utils

import "strings"

// 统计类型
type StatType byte

const (
	CountStat StatType = iota
	MaxStat
	MinStat
	LastStat
)

type CycleKey int

const (
	AllCycle CycleKey = iota
	DailyCycle
	WeeklyCycle
	MonthlyCycle
)

type EffectMode int

const (
	MultipleEffect EffectMode = iota
	FixedEffect
	DynamicEffect
	ResetEffect
)

func ConfigKeyParse(key string) (string, CycleKey) {
	ss := strings.Split(key, ":")
	return ss[0], CycleKey(ToInt(ss[1]))
}

type StatConfig struct {
	Key   string
	Cycle CycleKey
	Stat  StatType
}

func (config StatConfig) GetKey() string {
	return config.Key + ":" + ToString(config.Cycle)
}

func (config StatConfig) MergeStat(source *map[string]int32, value int32) {
	switch config.Stat {
	case MaxStat:
		v, ok := (*source)[config.Key]
		if !ok {
			(*source)[config.Key] = value
		} else if value > v {
			(*source)[config.Key] = value
		}
	case MinStat:
		v, ok := (*source)[config.Key]
		if !ok {
			(*source)[config.Key] = value
		} else if value < v {
			(*source)[config.Key] = value
		}
	case CountStat:
		v, ok := (*source)[config.Key]
		if !ok {
			(*source)[config.Key] = value
		} else {
			(*source)[config.Key] = v + value
		}
	case LastStat:
		(*source)[config.Key] = value
	}
}
